Data Visualization
In this tutorial, you’ll learn:
How to plot data variables that reside on unstructured grid elements (nodes, edges, faces)
Prerequisites
Concepts |
Importance |
Notes |
|---|---|---|
Necessary |
Time to learn: 10 minutes
Introduction
The previous section showcased how to visualize the geometry of unstructured grids by through Grid class. In this section, we will now visualize data variables that reside on unstructured elements
Data Mapping
Data variables that reside on unstructured grids can be mapped to different geometries, which impacts the choice of visualization method.
Face (Cell) Centered
Data is
Node (Vertex) Centered
Data
Edge Centered
import uxarray as ux
grid_path = "../../meshfiles/oQU480.grid.nc"
data_path = "../../meshfiles/oQU480.data.nc"
uxds = ux.open_dataset(grid_path, data_path)
Plotting Accessor
All plotting methods are accessed through the UxDataArray.plot accessor.
uxds["bottomDepth"].plot()
Polygons
The default plotting method for face-centered data variables is a raster polygon plot. Each cell/face in the unstructured grid is represented as a polygon, shaded with its corresponding data.
uxds["bottomDepth"].plot.polygons()
Rasterization
By default, rasterization (i.e. setting rasterize=False) is performed on the polygons to more efficiently render the grid. For higher-resolution grids, it is suggested to keep rasterize=True, since rendering each polygon directly takes a significant amount of time.
uxds["bottomDepth"].plot.polygons(rasterize=False)
Polygon Plots for Node/Edge Data
Polygon plotting is only supported for face-centered data variables, since each polygon must be shaded by a single value. If you are working with node or edge centered data, you must someone map that data to the faces.
One simple approach would be to perform a topological average of the node/edge centered data and store the result at the faces.
grid_path = "../../meshfiles/hex.grid.nc"
data_path = "../../meshfiles/hex.node.data.nc"
uxds_node_centered = ux.open_dataset(grid_path, data_path)
uxds_node_centered["random_data_node"].topological_mean(destination="face").plot()
In the example above, the average of the nodes that surround each face is computed and stored on the face, which allows the data to be visualuzed as polygons.
Points
Data can also be visualized as points, with the appropriate coordinates colored according to the node, edge, or face data.
Below, we can visualize our face-centered data variable by coloring the face-center coordinates with the corresponding data.
uxds["bottomDepth"].plot.points()
Rasterization
Just like with the polygon plots, we can also rasterize our points by setting rasterize=True
uxds["bottomDepth"].plot.points(rasterize=True)
For coarse resolutions, such as the one used in this example, the result looks significantly worse than the polygon plots. However, rasterized point plots can be extremely useful for visualuze high-resolution grids quickly, which is discussed in the Visualization High-Resolution Grids section.